package com.hyd.manage.service.impl;

import java.util.Collections;
import java.util.List;
import com.hyd.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.hyd.manage.mapper.MedicinesMapper;
import com.hyd.manage.domain.Medicines;
import com.hyd.manage.service.IMedicinesService;

/**
 * 药品入库Service业务层处理
 * 
 * @author hwb
 * @date 2025-02-20
 */
@Service
public class MedicinesServiceImpl implements IMedicinesService 
{
    @Autowired
    private MedicinesMapper medicinesMapper;

    /**
     * 查询药品入库
     * 
     * @param id 药品入库主键
     * @return 药品入库
     */
    @Override
    public Medicines selectMedicinesById(Long id)
    {
        return medicinesMapper.selectMedicinesById(id);
    }

    /**
     * 查询药品入库列表
     * 
     * @param medicines 药品入库
     * @return 药品入库
     */
    @Override
    public List<Medicines> selectMedicinesList(Medicines medicines)
    {
        return medicinesMapper.selectMedicinesList(medicines);
    }

    /**
     * 新增药品入库
     * 
     * @param medicines 药品入库
     * @return 结果
     */
    @Override
    public int insertMedicines(Medicines medicines)
    {
        medicines.setCreateTime(DateUtils.getNowDate());
        return medicinesMapper.insertMedicines(medicines);
    }

    /**
     * 修改药品入库
     * 
     * @param medicines 药品入库
     * @return 结果
     */
    @Override
    public int updateMedicines(Medicines medicines)
    {
        medicines.setUpdateTime(DateUtils.getNowDate());
        return medicinesMapper.updateMedicines(medicines);
    }

    /**
     * 批量删除药品入库
     * 
     * @param ids 需要删除的药品入库主键
     * @return 结果
     */
    @Override
    public int deleteMedicinesByIds(Long[] ids)
    {
        return medicinesMapper.deleteMedicinesByIds(ids);
    }

    /**
     * 删除药品入库信息
     * 
     * @param id 药品入库主键
     * @return 结果
     */
    @Override
    public int deleteMedicinesById(Long id)
    {
        return medicinesMapper.deleteMedicinesById(id);
    }

    /**
     * 根据药品编码查询药品信息
     * @param medicineCode
     * @return
     */
    @Override
    public List<Medicines> selectMedicinesListByCode(String medicineCode) {
        return medicinesMapper.selectMedicinesListByCode(medicineCode);
    }

    /**
     * 根据药品编码更新库存数量
     * @param medicineCode
     * @param quantity
     * @return
     */
    @Override
    public int updateStockQuantity(String medicineCode, String batchNumber, Long quantity) {
        return medicinesMapper.updateStockQuantity(medicineCode, batchNumber, quantity);
    }

    /**
     * 根据药品编码更新库存数量(增加)
     * @param medicineCode
     * @param quantity
     * @return
     */
    @Override
    public int updateStockQuantityAdd(String medicineCode, String batchNumber, Long quantity) {
        return medicinesMapper.updateStockQuantityAdd(medicineCode, batchNumber, quantity);
    }

    /**
     * 根据药品编码查询库存信息
     * @param medicineCode
     * @return
     */
    @Override
    public List<Medicines> selectInventoryByCode(String medicineCode) {
        return medicinesMapper.selectInventoryByCode(medicineCode);
    }

    /**
     * 根据药品编码和批次号查询药品信息
     * @param medicineCode
     * @param batchNumber
     * @return
     */
    @Override
    public Medicines selectMedicineByCodeAndNumber(String medicineCode, String batchNumber) {
        return medicinesMapper.selectMedicineByCodeAndNumber(medicineCode, batchNumber);
    }
}
